// component/subject/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    title:{
      type:String,
      value:''
    },
    subjectData:{
      type:Array,
      value:[]
    },
    subjectIndex:{
      type:Number,
      value:0
    },
    model:{
      type: String,
      value: ''
    },
    date:{
      type: String,
      value: ''
    },
    placeholder:{
      type: String,
      value: ''
    },
    starNum:{
      type: Number,
      value: 0
    },
    star:{
      type:Array,
      value:[[],[],[],[],[]]
    },
    tip:{
      type: Array,
      value: []
    },
    finished:{
      type:Boolean,
      value:false
    },
    content:{
      type: String,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    clickAction(e){
      if (this.properties.finished){
        return
      }
      var data = this.properties.subjectData
      for(var i = 0;i<this.properties.subjectData.length;i++){
        if (this.properties.model == 'RADIO'){
          if (Number(e.currentTarget.id) == i) {
            data[i].isSelected = true
          } else {
            data[i].isSelected = false
          }
        } else if (this.properties.model == 'CHECK_BOX'){
          if (Number(e.currentTarget.id) == i) {
            data[i].isSelected = !data[i].isSelected
          }
        }
       
      }
      this.setData({
        subjectData: data
      })
      this.triggerEvent('chooseAction', {
        index: this.properties.subjectIndex,
        data: this.properties.subjectData
      })
    },
    bindDateChange(e){
      if (this.properties.finished) {
        return
      }
      console.log(e)
      this.setData({
        content:e.detail.value
      })
      this.triggerEvent('chooseAction', {
        index: this.properties.subjectIndex,
        data: this.properties.content
      })
    },
    clickevaluateImg(e){
      if (this.properties.finished) {
        return
      }
      console.log(e)
      this.setData({
        starNum:Number(e.currentTarget.id)+1
      })
      this.triggerEvent('chooseAction', {
        index: this.properties.subjectIndex,
        data: this.properties.starNum
      })
    },
    bindinput(e){
      if (this.properties.finished) {
        return
      }
      console.log(e)
      this.triggerEvent('chooseAction', {
        index: this.properties.subjectIndex,
        data: e.detail.value
      })
    },
    touchMoved(e){
      console.log(e)
    }
  }
})
